package sge.Datos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import sge.Datos.ClienteMySQL;
import sge.Datos.Conexion;

public class FabricaConexion extends ClienteMySQL{
    /*
    private final String driver     = "com.mysql.jdbc.Driver";
    private final String name_dir   = "jdbc:mysql://mysql:3306/danielha";
    private final String user_db    = "danielha";
    private final String pass_db    = "danielha";
        */
        /*String driverClassName = "com.mysql.jdbc.Driver";
        String connectionUrl = "jdbc:mysql://localhost:3306/bd_sge";
        String dbUser = "root";
        String dbPwd = "51f52916e6";*/

        private static FabricaConexion instanciaConexion = null;

        private FabricaConexion() {
                super();
        }

        /*public Connection getConexion() throws SQLException {
                Connection conn = null;
                conn = DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
                return conn;
        */
        
        public static Vector consulta(String query) throws SQLException{
        	Vector data = new Vector();
        	
        	Statement sentencia;
        	sentencia = getInstancia().getConexion().createStatement();
			ResultSet rs = sentencia.executeQuery(query);
			int cols= rs.getMetaData().getColumnCount();
					
			while (rs.next()) {
				Vector<String> temp = new Vector<String>();
				for (int i = 1; i <= cols; i++) {
					temp.add(rs.getString(i));
				}
				data.add(temp);
			}
			for (int i = 0; i < data.size(); i++) {
				for (int j = 0; j < ((Vector) data.get(i)).size(); j++) {
					System.out.println("("+i+", "+j+")="+((Vector) data.get(i)).get(j));
				}
			}
			return data;
        	
        }
        
        public static Vector columna(String query) throws SQLException{
        	Vector data = new Vector();
        	
        	Statement sentencia;
        	sentencia = getInstancia().getConexion().createStatement();
			ResultSet rs = sentencia.executeQuery(query);
			int cols= rs.getMetaData().getColumnCount();
					
			while (rs.next()) {
				
					data.add(rs.getString(1));
			}
			return data;
        	
        }

        public static FabricaConexion getInstancia() {
            
                if (instanciaConexion == null) {
                        instanciaConexion = new FabricaConexion();
                       
                }
                return instanciaConexion;
        }
}
